package com.autoagent.ai_live_master.webSocket.controller;

import com.autoagent.ai_live_master.webSocket.service.FormulaicScriptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 定式话术控制器
 * 用于管理定式话术功能
 */
@Slf4j
@RestController
@RequestMapping("/live/formulaic-script")
public class FormulaicScriptController {

    @Autowired
    private FormulaicScriptService formulaicScriptService;

    /**
     * 测试根据房间ID获取定式话术
     * 
     * @param roomId 房间ID
     * @return 定式话术内容
     */
    @GetMapping("/{roomId}")
    public String getFormulaicScript(@PathVariable String roomId) {
        log.info("测试获取定式话术，房间ID: {}", roomId);
        String script = formulaicScriptService.getFormulaicScriptByRoomId(roomId);
        log.info("获取到定式话术，房间ID: {}, 内容长度: {}", roomId, script.length());
        return script;
    }

    /**
     * 清除指定房间的缓存
     * 
     * @param roomId 房间ID
     * @return 操作结果
     */
    @DeleteMapping("/cache/{roomId}")
    public String clearCache(@PathVariable String roomId) {
        log.info("清除定式话术缓存，房间ID: {}", roomId);
        formulaicScriptService.clearCache(roomId);
        return "缓存已清除";
    }

    /**
     * 清除所有缓存
     * 
     * @return 操作结果
     */
    @DeleteMapping("/cache")
    public String clearAllCache() {
        log.info("清除所有定式话术缓存");
        formulaicScriptService.clearAllCache();
        return "所有缓存已清除";
    }

    /**
     * 获取缓存大小
     * 
     * @return 缓存大小
     */
    @GetMapping("/cache/size")
    public int getCacheSize() {
        int size = formulaicScriptService.getCacheSize();
        log.info("当前缓存大小: {}", size);
        return size;
    }
}
